﻿using System;
using System.Threading;
using MS.Internal.Mita.Foundation;

namespace UIAStudio
{
    public class InitUIATreeViewWorkItem : WorkItem
    {
        private UIATreeView _uiaTreeView;

        public InitUIATreeViewWorkItem(WorkQueue queue, UIATreeView uiaTV)
            : base(queue)
        {
            _uiaTreeView = uiaTV;
        }

        public override void Execute()
        {
            //int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
            //UIFilter filter = String.Format("ProcessId!={0}", pid);
            UIATreeNode rootNode = new UIATreeNode(UIObject.Root);
            rootNode.Nodes.Add("");
            ThreadStart ts = delegate
            {
                _uiaTreeView.Nodes.Add(rootNode);
                _uiaTreeView.SelectedNode = rootNode;
            };
            _uiaTreeView.Invoke(ts);
            
            //UICollection<UIObject> children = UIObject.Root.Children;
            //children = children.FindAll(String.Format("ProcessId!={0}", pid));
            //PopulationWorkItem populationWorkItem = new PopulationWorkItem(Queue, rootNode, 1, filter);
            //Queue.Enqueue(populationWorkItem);
            //foreach (UIObject child in children)
            //{
            //    rootNode.Nodes.Add(new UIATreeNode(child));

            //}
            //_uiaTreeView.Nodes.Add(rootNode);
        }
    }
}
